classdef SimpleObjectiveCounter < handle
    %UNTITLED2 Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods
        function [o,sp] = compute(obj, ind)
            mask = mask_generator( ind.connections );
            graph_distances = ind.stops_handle.distances + mask;
            ind.shortest_paths = FastFloyd(graph_distances);
            
            % Sprawdzenie spojnosci
            if find( ind.shortest_paths == inf )
                %disp( 'Graf niespojny' )
                sp = false;
            else
                %disp( 'Graf spojny' )
                sp = true;
            end
            
            % Korekcja macierzy - patrz conectivty_test1
            
            max_distance = max(max(ind.stops_handle.distances));
            scale_factor = 500;
            for i=1:ind.stops_handle.number
                for j=1:ind.stops_handle.number
                    if(ind.shortest_paths(i,j) == Inf)
                        ind.shortest_paths(i,j) = max_distance * scale_factor ;
                    end
                end
            end
            %ind.stops_handle.number
            %b=1000000000000; %TODO: refactor
            ind.total_cost = cost(ind.stops_handle.costs, ind.connections );
            o = objective(ind.shortest_paths.^2, ind.stops_handle.wages, ind.total_cost );
            
%             G = tril(ind.stops_handle.costs);
%             DG = sparse(G);
%             UG = tril(DG + DG');
%             [a,b] = graphminspantree(UG);
%             A = full(a);
%             t = cost(A, ones(length(A)));
% 
%             
%             if ind.total_cost > 2*t
%                 o = 2*o;
%             end
            
            ind.objective_value = o;
        end
    end
  
end

